home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / muds / mordor_2.000 / mordor_2 / src / command11.c < prev    next >
C/C++ Source or Header  |  1995-06-28  |  11KB  |  454 lines

  1. /*
  2.  * COMMAND11.C:
  3.  * 
  4.  *
  5.  *   Additional user routines
  6.  *
  7.  */
  8.  
  9. #include "mstruct.h"
  10. #include "mextern.h"
  11. #include <sys/types.h>
  12. #include <sys/stat.h>
  13. #include <time.h>
  14.  
  15. /******************************************************************/
  16. /*                emote                  */
  17. /******************************************************************/
  18.  
  19. /* This command allows a player to echo a message unaccompanied by */
  20. /* any message format, except for the players name at the beginning */
  21.  
  22. int emote(ply_ptr, cmnd)
  23. creature    *ply_ptr;
  24. cmd        *cmnd;
  25. {
  26.     room        *rom_ptr;
  27.     int        index = -1, i, fd;
  28.  
  29.     fd = ply_ptr->fd;
  30.     rom_ptr = ply_ptr->parent_rom;
  31.  
  32.     for(i=0; i<strlen(cmnd->fullstr) && i < 256; i++) {
  33.         if(cmnd->fullstr[i] == ' ') {
  34.             index = i + 1;
  35.             break;
  36.         }
  37.     }
  38.     cmnd->fullstr[255] = 0;
  39.  
  40.     if(index == -1 || strlen(&cmnd->fullstr[index]) < 1) {
  41.         print(fd, "Emote what?\n");
  42.         return(0);
  43.     }
  44.     if(F_ISSET(ply_ptr, PSILNC)){
  45.         print(fd, "You are unable to do that right now.\n");
  46.         return(0);
  47.     }
  48.     F_CLR(ply_ptr, PHIDDN);
  49.     if(F_ISSET(ply_ptr, PLECHO)){
  50.                 ANSI(fd, CYAN);
  51.                 print(fd, "You emote: %s\n", &cmnd->fullstr[index]);
  52.                 ANSI(fd, NORMAL);
  53.         }
  54.         else
  55.         print(fd, "Ok.\n");
  56.  
  57.     broadcast_rom(fd, rom_ptr->rom_num, "%M %s", 
  58.             ply_ptr, &cmnd->fullstr[index]);
  59.  
  60.     return(0);
  61. }
  62. /*==============================================================*/
  63. /*                          passwd                              */
  64. /*==============================================================*/
  65. /* The passwd function callls the necessary function to allow *
  66.  * a player to change their password. */
  67.  
  68. int passwd (ply_ptr, cmnd)
  69. creature    *ply_ptr;
  70. cmd     *cmnd;   
  71. {
  72. int    fd;
  73. extern void chpasswd();
  74.     fd = ply_ptr->fd;
  75.  
  76.         /* do not flash output until player hits return */
  77.         F_SET(Ply[fd].ply, PREADI); 
  78.         chpasswd(fd,0,"");
  79.         return(DOPROMPT);
  80.                          
  81. }
  82. /*==============================================================*/
  83. /*                       chpasswd                               */
  84. /*==============================================================*/
  85. /* The chpasswd command handles  the procedure involved in       *
  86.  * changing a player's password.  A player first must enter the  *
  87.  * correct current password, then the new password, and re enter *
  88.  * the new password to comfirm it. If the player enters the      *
  89.  * wrong password  or an invalid password (too short or long),   *
  90.  * the password will not be changed and the procedure is aborted. */
  91.  
  92. void chpasswd(fd,param,str)
  93. int    fd;
  94. int    param;
  95. char *str;
  96. {
  97.     creature    *ply_ptr;
  98.  
  99.  
  100.     ply_ptr = Ply[fd].ply;
  101.     output_buf();
  102.     switch (param) {
  103.     case 0:
  104.             print(fd,"Current password: ");
  105.              output_buf();
  106.             Ply[fd].io->intrpt &= ~1; 
  107.             RETURN(fd,chpasswd,1);
  108.     break;
  109.     case 1:
  110.         if (!strcmp(ply_ptr->password,str)){
  111.             print(fd, "%c%c%c\n\r", 255, 252, 1);
  112.             print(fd,"New passowrd: ");
  113.              output_buf();
  114.             Ply[fd].io->intrpt &= ~1; 
  115.             RETURN(fd,chpasswd,2);
  116.         }
  117.         else {
  118.             print(fd, "%c%c%c\n\r", 255, 252, 1);
  119.             print(fd,"incorrect password.\n");
  120.             print(fd,"Aborting.\n");
  121.             F_CLR(Ply[fd].ply, PREADI);
  122.             RETURN(fd, command, 1);
  123.         }
  124.     case 2:
  125.             if (strlen(str) <3){
  126.             print(fd, "%c%c%c\n\r", 255, 252, 1);
  127.                 print(fd,"Password too short.\n");
  128.                 print(fd,"Aborting.\n");
  129.                 F_CLR(Ply[fd].ply, PREADI);
  130.                 RETURN(fd, command, 1);
  131.             }
  132.             else if (strlen(str) > 14){
  133.             print(fd, "%c%c%c\n\r", 255, 252, 1);
  134.                 print(fd,"Password too long.\n");
  135.                 print(fd,"Aborting.\n");
  136.                 F_CLR(Ply[fd].ply, PREADI);
  137.                 RETURN(fd, command, 1);
  138.             }
  139.             else{
  140.                 strcpy(Ply[fd].extr->tempstr[1], str);
  141.             print(fd, "%c%c%c\n\r", 255, 252, 1);
  142.                 print(fd,"Enter re-enter password: ");
  143.                  output_buf();
  144.                 Ply[fd].io->intrpt &= ~1; 
  145.                 RETURN(fd,chpasswd,3);
  146.             }
  147.     break;
  148.     case 3:
  149.         if(!strcmp(Ply[fd].extr->tempstr[1],str)){
  150.             strcpy(ply_ptr->password,str);
  151.             print(fd, "%c%c%c\n\r", 255, 252, 1);
  152.             print(fd,"password changed.\n");
  153.                F_CLR(Ply[fd].ply, PREADI);
  154.             save_ply(ply_ptr->name,ply_ptr);
  155.             RETURN(fd, command, 1);
  156.         }
  157.         else{
  158.             print(fd, "%c%c%c\n\r", 255, 252, 1);
  159.             print(fd,"different passwords given.\n");
  160.             print(fd,"Aborting.\n");
  161.                F_CLR(Ply[fd].ply, PREADI);
  162.             RETURN(fd, command, 1);
  163.         }
  164.     break;
  165.  
  166.     }
  167.  
  168. }
  169.  
  170.  
  171. /*==============================================================*/
  172. int vote (ply_ptr, cmnd)
  173. creature    *ply_ptr;
  174. cmd     *cmnd;   
  175. {
  176.     int        fd;
  177.     int     i,n, number;
  178.     int        match = 0;
  179.     char    str[80], tmp[256];
  180.     FILE    *fp;
  181. extern void vote_cmnd();
  182.     
  183.     fd = ply_ptr->fd;
  184.     str[0] = 0; 
  185.     if ((18 + ply_ptr->lasttime[LT_HOURS].interval/86400L) < 21) {
  186.         print(fd, "You're too young to vote in this election.\n");
  187.         return(0);
  188.     }
  189.     if (!F_ISSET(ply_ptr->parent_rom,RELECT)){
  190.         print(fd,"This is not an electon booth.\n");
  191.         return(0);
  192.     }
  193.  
  194.     sprintf(Ply[fd].extr->tempstr[0],"%s/ISSUE",POSTPATH);
  195.     fp = fopen(Ply[fd].extr->tempstr[0],"r");
  196.     if(!fp){
  197.         print(fd,"There are currently no issues for you to vote on.\n");
  198.         return(0);
  199.     }
  200.     
  201.     fgets(tmp, 256,fp);
  202.     if (feof(fp)) {
  203.         print(fd,"Currently there are no issues for you to vote on.\n");
  204.         return(0);
  205.     }
  206.     fclose(fp);
  207.  
  208.     n =  sscanf(tmp,"%d %s",&number,str);
  209.  
  210.     lowercize(str,1);
  211.     if (n <1){
  212.         print(fd,"There are no issues for you to vote on at this time.\n");
  213.         return(0);
  214.     } else if (n == 2 && str){
  215.         if(!strcmp(str,"Prince0") && F_ISSET(ply_ptr,PPLDGK)
  216.             && !F_ISSET(ply_ptr,PKNGDM))
  217.             match = 1;
  218.         else if(!strcmp(str,"Prince1") && F_ISSET(ply_ptr,PPLDGK)
  219.             && F_ISSET(ply_ptr,PKNGDM))
  220.             match = 1;
  221.         else
  222.             for (i=1;i<CARETAKER; i++)
  223.                 if(!strcmp(str,class_str[i])){
  224.                     if(i == ply_ptr->class)
  225.                         match = 1;
  226.                     break;
  227.                 }
  228.  
  229.         if(!match){
  230.             print(fd,"Sorry, you may not vote in this election.\n");
  231.             return(0);
  232.         }
  233.     }
  234.  
  235.     Ply[fd].extr->tempstr[1][0] = MIN(79,number);
  236.     Ply[fd].extr->tempstr[1][1] = 0;
  237.     
  238.     
  239.      F_SET(Ply[fd].ply, PREADI); 
  240.     vote_cmnd(fd,0,"");
  241.     return(DOPROMPT);
  242.                          
  243. }
  244. /*==============================================================*/
  245. void vote_cmnd(fd,param,str)
  246. int     fd;
  247. int     param;
  248. char *str;
  249. {
  250.     creature    *ply_ptr;
  251.         int        i, n =0;
  252.         char    tmp[1024], c;
  253.         FILE    *fp;
  254.     
  255.         ply_ptr = Ply[fd].ply;
  256.  
  257.         output_buf();
  258.         switch (param) {
  259.         case 0:
  260.             sprintf(tmp,"%s/vote/%s_v",PLAYERPATH,ply_ptr->name);
  261.             fp = fopen(tmp,"r");
  262.             if (!fp){
  263.                 fp = fopen(Ply[fd].extr->tempstr[0],"r");
  264.                 if(!fp) {
  265.                     F_CLR(Ply[fd].ply, PREADI);
  266.                     RETURN(fd, command, 1);
  267.                 }
  268.  
  269.                 fgets(tmp,1024,fp);
  270.                 fgets(tmp,1024,fp);
  271.                 tmp[1023] = 0;
  272.                 fclose(fp);
  273.                 print(fd,"\n%s",tmp);
  274.                 print(fd,"How do you vote: ");
  275.                 output_buf();
  276.  
  277.                 Ply[fd].extr->tempstr[1][1] = 1;
  278.                 Ply[fd].io->intrpt &= ~1; 
  279.                 RETURN(fd,vote_cmnd,2);
  280.             }
  281.             else {
  282.                 fclose(fp);
  283.                 print(fd,"You have already voted.\n");
  284.                 print(fd,"Do you wish to change your vote (y/n): ");
  285.                 output_buf();
  286.                 Ply[fd].io->intrpt &= ~1; 
  287.                 RETURN(fd,vote_cmnd,1);
  288.             }
  289.         break;
  290.         case 1:
  291.             if (str[0] == 'y' || str[0] == 'Y'){
  292.                 sprintf(tmp,"%s/vote/%s_v",PLAYERPATH,ply_ptr->name);
  293.                 unlink(tmp);
  294.  
  295.                 fp = fopen(Ply[fd].extr->tempstr[0],"r");
  296.                 if(!fp) {
  297.                     F_CLR(Ply[fd].ply, PREADI);
  298.                     RETURN(fd, command, 1);
  299.                 }
  300.  
  301.                 fgets(tmp,1024,fp);
  302.                 fgets(tmp,1024,fp);
  303.                 tmp[1023] = 0;
  304.                 fclose(fp);
  305.                 print(fd,"\n%s",tmp);
  306.                 print(fd,"How do you vote: ");
  307.                 output_buf();
  308.  
  309.                 Ply[fd].extr->tempstr[1][1] = 1;
  310.                 Ply[fd].io->intrpt &= ~1; 
  311.                 RETURN(fd,vote_cmnd,2);
  312.             }
  313.             print(fd,"Aborting.\n");
  314.             F_CLR(Ply[fd].ply, PREADI);
  315.             RETURN(fd, command, 1);
  316.  
  317.         break;
  318.         case 2:
  319.             c = low(str[0]);
  320.             if (c != 'a' && c != 'b' && c != 'c' && c != 'd' && c != 'e' && c != 'f' && c != 'g'){
  321.                 print(fd,"Invalid selection. Aborting\n");
  322.                 F_CLR(Ply[fd].ply, PREADI);
  323.                 RETURN(fd, command, 1);
  324.             }
  325.             n = MAX(0,Ply[fd].extr->tempstr[1][1] -1);
  326.             Ply[fd].extr->tempstr[2][n] = up(c);
  327.             if (Ply[fd].extr->tempstr[1][1] >= Ply[fd].extr->tempstr[1][0]){
  328.                 vote_cmnd(fd,3,"");
  329.                 RETURN(fd,command,1);
  330.             }
  331.             else{
  332.                 fp = fopen(Ply[fd].extr->tempstr[0],"r");
  333.                 if(!fp) {
  334.                     F_CLR(Ply[fd].ply, PREADI);
  335.                     RETURN(fd, command, 1);
  336.                 }
  337.  
  338.                 fgets(tmp,1024,fp);
  339.                 if (feof(fp)) {
  340.                     F_CLR(Ply[fd].ply, PREADI);
  341.                     RETURN(fd, command, 1);
  342.                 }
  343.     
  344.                 n = 0;
  345.                 while(!feof(fp)){
  346.                     fgets(tmp,1024,fp);
  347.                     tmp[1023] = 0;
  348.                     n++;
  349.                     if ( n  == Ply[fd].extr->tempstr[1][1]+1)
  350.                         break;
  351.                 }
  352.                 print(fd,"\n%s",tmp);
  353.                 print(fd,"How do you vote: ");
  354.                 output_buf();
  355.  
  356.                 Ply[fd].extr->tempstr[1][1] = n;
  357.                 fgets(tmp,1024,fp);
  358.                 if (feof(fp))
  359.                     Ply[fd].extr->tempstr[1][0] = Ply[fd].extr->tempstr[1][1];
  360.                 fclose(fp);
  361.     
  362.                    Ply[fd].io->intrpt &= ~1; 
  363.                 RETURN(fd,vote_cmnd,2);
  364.             }
  365.         break;
  366.  
  367.         case 3:
  368.             n = Ply[fd].extr->tempstr[1][0] ;
  369.             sprintf(tmp,"%s/vote/%s_v",PLAYERPATH,ply_ptr->name);
  370.             Ply[fd].extr->tempstr[2][n] = 0;
  371.             i = open(tmp, O_CREAT | O_RDWR, ACC);
  372.             if(i < 0)
  373.                 merror("vote_cmnd", FATAL);
  374.                                           
  375.             write(i,Ply[fd].extr->tempstr[2],n);
  376.             close(i);
  377.             print(fd,"voted.\n");
  378.             F_CLR(Ply[fd].ply, PREADI);
  379.             RETURN(fd, command, 1);
  380.         break;
  381.     }
  382. }
  383.  
  384. /*************************************************************************/
  385. /*                              pfinger                                  */
  386. /*************************************************************************/
  387. int pfinger(ply_ptr, cmnd) 
  388. creature    *ply_ptr;
  389. cmd        *cmnd;
  390. {
  391.  
  392.     struct stat f_stat;
  393.     creature    *player;
  394.     char        tmp[80];
  395.     int            fd;
  396.  
  397.     fd = ply_ptr->fd; 
  398.     if(cmnd->num < 2) {
  399.         print(fd, "Finger who?\n");
  400.         return(0);
  401.     }
  402.     cmnd->str[1][0] = up(cmnd->str[1][0]);
  403.     player = find_who(cmnd->str[1]);
  404.  
  405.     if (!player){
  406.  
  407.         if(load_ply(cmnd->str[1], &player) < 0){
  408.                print(fd,"Player does not exist.\n");
  409.                return (0);
  410.         }             
  411.  
  412.       if (ply_ptr->class < CARETAKER && (player->class == CARETAKER ||
  413.           player->class == DM)) {
  414.             print(fd,"You are currently unable to finger that player.\n");
  415.             return (0);
  416.         }
  417.  
  418.         sprintf(tmp,"%s/%s",PLAYERPATH,cmnd->str[1]);
  419.         if (stat(tmp,&f_stat)){
  420.                print(fd,"Player does not exist.\n");
  421.                return (0);
  422.         }
  423.  
  424.         print(fd,"%s %+25s %+15s\n",player->name, 
  425.                 race_str[player->race], title_ply(player));
  426.         print(fd,"last login: %s",ctime(&f_stat.st_ctime));
  427.         free_crt(player);
  428.     } 
  429.     else{
  430.         if (F_ISSET(player, PDMINV) && 
  431.           (ply_ptr->class < CARETAKER || (ply_ptr->class == CARETAKER &&
  432.           player->class == DM))) {
  433.             print(fd,"You are currently unable to finger that player.\n");
  434.             return (0);
  435.         }
  436.  
  437.         print(fd,"%s %+25s %+15s\n",player->name, 
  438.                 race_str[player->race], title_ply(player));
  439.         print(fd,"Currently logged on.\n");
  440.     }
  441.  
  442.     sprintf(tmp,"%s/%s",POSTPATH,cmnd->str[1]);
  443.     if (stat(tmp,&f_stat)){
  444.        print(fd,"No mail.\n");
  445.        return (0);
  446.     }
  447.  
  448.     if (f_stat.st_atime > f_stat.st_ctime)
  449.         print(fd,"No unread mail since: %s",ctime(&f_stat.st_atime));
  450.      else
  451.         print(fd,"New mail since: %s",ctime(&f_stat.st_ctime));
  452.  
  453. }
  454.